#pragma once


template <class T> class CSmartPtr
{
public:
	CSmartPtr() {m_ptr = NULL;}
	CSmartPtr(T *p_ptr) {m_ptr = p_ptr; 
						if(m_ptr) m_ptr->IncRef();}
	CSmartPtr(CSmartPtr &p_ptr) {m_ptr=p_ptr.m_ptr; 
						if(m_ptr) m_ptr->IncRef();}
	~CSmartPtr() {Clear();}

	void Clear() {if(m_ptr) {m_ptr->DecRef(); 
						m_ptr =NULL;} }
	T *operator=(T *t) {if(t) t->IncRef(); 
						Clear(); 
						m_ptr = t; 
						return m_ptr;}
	T *operator=(CSmartPtr *t) {if(t.m_ptr) t.m_ptr->IncRef();
						Clear(); 
						m_ptr = t.m_ptr; 
						return m_ptr;}
	operator T *() const {return m_ptr;}
	T * operator->() const {return m_ptr;}

private:
	T *m_ptr;
};